﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using Panny.Data;
using System.ComponentModel;
namespace Controller
{
    [DataObject()]
   public class CouponShow
    {
       public DataSet GetIndexTop6(string areaid)
       {
           string sql = " select top 6 Coupons.[ImageSrc],Coupons.Title,b.Title as CorpTitle,[Save],CouponID,EndDate,b.CorpID from Coupons inner join CorpInfo b on b.CorpID = Coupons.CorpID where EndDate>getdate() and b.AreaID=@AreaID order by Coupons.hits desc,Coupons.CreateOn desc";
           using (SqlText selection = new SqlText(sql))
           {
               selection.AddParameter("@AreaID", areaid);
               return selection.GetDataset();
           }
       }
       public DataSet GetRight_iframe_top5(string areaid)
       {
           string sql = " select top 5 Coupons.[ImageSrc],Coupons.Title,b.Title as CorpTitle,[Save],CouponID,EndDate,b.CorpID from Coupons inner join CorpInfo b on b.CorpID = Coupons.CorpID where EndDate>getdate() and b.AreaID=@AreaID  order by b.hits desc,Coupons.CreateOn desc";
           using (SqlText selection = new SqlText(sql))
           {

               selection.AddParameter("@AreaID", areaid);
               return selection.GetDataset();
           }
       }

       [DataObjectMethod(DataObjectMethodType.Select)]
       public DataSet GetEr_IndexTop106(string areaid,string typeid)
       {
           string sql = "select top 6 Coupons.[ImageSrc],Coupons.Title,b.Title as CorpTitle,[Save],CouponID,EndDate,b.CorpID from Coupons inner join CorpInfo b on b.CorpID = Coupons.CorpID where EndDate>getdate() and b.AreaID=@AreaID  and b.TypeID=@TypeID  order by Coupons.CreateOn desc";
           using (SqlText selection = new SqlText(sql))
           {

               selection.AddParameter("@AreaID", areaid);
               selection.AddParameter("@TypeID", typeid);
               return selection.GetDataset();
           }
       }
       [DataObjectMethod(DataObjectMethodType.Select)]
       public DataSet So(string areaID,string typeid,string key)
       {
           StringBuilder sql = new StringBuilder();
           sql.Append("  select top 6 Coupons.[ImageSrc],[Desc],CouponID,Coupons.Title,b.Title as CorpTitle,[Save],CouponID,BeginDate,EndDate,b.CorpID,b.TypeID");
           sql.Append(" ,b.Address,b.Telphone,Coupons.Hits,Coupons.CreateOn from Coupons inner join CorpInfo b on b.CorpID = Coupons.CorpID where EndDate>getdate() ");
           sql.Append(" and b.AreaID=@AreaID  and (@TypeID = 0 or @TypeID is null or b.TypeID=@TypeID ) ");
           if (!string.IsNullOrEmpty(key))
           {
               sql.AppendFormat(" and Coupons.Title like '%{0}%'", key);
           }
           sql.Append(" order by Coupons.Hits desc,Coupons.CreateOn desc ");
           using (SqlText selection = new SqlText(sql.ToString()))
           {

               selection.AddParameter("@AreaID", areaID);
               selection.AddParameter("@TypeID", typeid);
               return selection.GetDataset();
           }
       }



    }
}
